package com.project.action;

import java.util.List;

import net.sf.json.JSONArray;

import com.project.entity.*;
import com.project.service.*;
public class ExpertManageAction {
	
	private Integer start;//前台传回的页码
	private Integer limit;//固定每页显示记录数量为20.
	
    private Integer expertid;
    private String name;
    private String identitycardnumber;
    private String unit;
    private String jobtitle;
    private String major;
    private String contactinformation;
    private String unitaddress;
    private String homeaddress;
    private String attachment;
    
    
    private String		jsonString;//使用json传递数据
	private ExpertManage	 expertManageService;  //service
	
	//获取全部专家信息
	public String getAllExpert(){
		if(start ==null||start<=0){
			this.start = 1;
		}
		List<Expert> expertList = this.expertManageService.getAllExpert(start,start+limit);
		JSONArray jsonObject = JSONArray.fromObject(expertList);
		this.setJsonString("{success:true,totalCount : " + expertList.size()
				+ ", list:" + jsonObject.toString() + "}");
		return "success";
	}

	//添加专家信息
	public String addExpert(){
		Expert expert = new Expert();
		expert.setAttachment(attachment);
		expert.setContactinformation(contactinformation);
	//	expert.setExpertid(expertid);
		expert.setHomeaddress(homeaddress);
		expert.setIdentitycardnumber(identitycardnumber);
		expert.setJobtitle(jobtitle);
		expert.setMajor(major);
		expert.setName(name);
		expert.setUnit(unit);
		expert.setUnitaddress(unitaddress);
		
		this.expertManageService.insertExpert(expert);
		
		JSONArray jsonObject = JSONArray.fromObject(expert);
		this.setJsonString("{success:true,totalCount : " + "1"
				+ ", object:" + jsonObject.toString() + "}");
		return "success";
	}
	
	//修改专家信息
	public String updateExpert(){
		Expert expert = new Expert();
		expert.setAttachment(attachment);
		expert.setContactinformation(contactinformation);
		expert.setExpertid(expertid);
		expert.setHomeaddress(homeaddress);
		expert.setIdentitycardnumber(identitycardnumber);
		expert.setJobtitle(jobtitle);
		expert.setMajor(major);
		expert.setName(name);
		expert.setUnit(unit);
		expert.setUnitaddress(unitaddress);

		this.expertManageService.updateById(expert);
		
		JSONArray jsonObject = JSONArray.fromObject(expert);
		this.setJsonString("{success:true,totalCount : " + "1"
				+ ", object:" + jsonObject.toString() + "}");
		return "success";
	}
	
	//根据ID删除专家信息
	public String deleteExpert(){
		if(this.expertid!=null){
			this.expertManageService.deleteById(expertid);
		}
		this.setJsonString("{success:true}");
		return "success";
	}
	
	
	/** getter  and  setter~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**/	
	public Integer getExpertid() {
		return expertid;
	}


	public void setExpertid(Integer expertid) {
		this.expertid = expertid;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getIdentitycardnumber() {
		return identitycardnumber;
	}


	public void setIdentitycardnumber(String identitycardnumber) {
		this.identitycardnumber = identitycardnumber;
	}


	public String getUnit() {
		return unit;
	}


	public void setUnit(String unit) {
		this.unit = unit;
	}


	public String getJobtitle() {
		return jobtitle;
	}


	public void setJobtitle(String jobtitle) {
		this.jobtitle = jobtitle;
	}


	public String getMajor() {
		return major;
	}


	public void setMajor(String major) {
		this.major = major;
	}


	public String getContactinformation() {
		return contactinformation;
	}


	public void setContactinformation(String contactinformation) {
		this.contactinformation = contactinformation;
	}


	public String getUnitaddress() {
		return unitaddress;
	}


	public void setUnitaddress(String unitaddress) {
		this.unitaddress = unitaddress;
	}


	public String getHomeaddress() {
		return homeaddress;
	}


	public void setHomeaddress(String homeaddress) {
		this.homeaddress = homeaddress;
	}


	public String getAttachment() {
		return attachment;
	}


	public void setAttachment(String attachment) {
		this.attachment = attachment;
	}


	public String getJsonString() {
		return jsonString;
	}


	public void setJsonString(String jsonString) {
		this.jsonString = jsonString;
	}


	public ExpertManage getExpertManageService() {
		return expertManageService;
	}


	public void setExpertManageService(ExpertManage expertManageService) {
		this.expertManageService = expertManageService;
	}

	public Integer getStart() {
		return start;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	public Integer getLimit() {
		return limit;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}
	
}
